using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using Mpi.Common.Collections;
using Xeml.Document;
using Xeml.Document.Contracts;
using Xeml.SQLDataProviders;

namespace Xeml.Sampling.Contracts
{
    public interface IDataProvider : IXemlComponent
    {
        /// <summary>
        /// An optional logo for the provider
        /// </summary>
        Image Logo
        {
            get;
        }

        /// <summary>
        /// Get the configuration of this component
        /// </summary>
        DataProviderConfiguration Configuration
        {
            get;
        }

        /// <summary>
        /// Indicates whether or not the provider supports automapping.
        /// </summary>
        bool SupportsAutoMapping
        {
            get;
        }

        /// <summary>
        /// Returns a list of keys to identify samples within the data source
        /// </summary>
        /// <returns>List of key names</returns>
        IEnumerable<string> ListForeignKey();

        /// <summary>
        /// Returns a list of possible values to a given key
        /// </summary>
        /// <param name="key">The key</param>
        /// <returns>List of values</returns>
        IEnumerable<string> FilterKeyValues(string key, Dictionary<string,string> filter);
        
        /// <summary>
        /// Maps samples automatically
        /// </summary>
        /// <param name="samples">The sample identifiere to map</param>
        /// <returns>A list of sample id mappings</returns>
        IEnumerable<SidMapping> AutoMap(Guid expId, string expName, IEnumerable<int> samples);

        /// <summary>
        /// Validates the existence of an sample.
        /// </summary>
        /// <param name="sim">The sample to validate.</param>
        /// <returns>An value indicting whether the sample exist or not.</returns>
        SidLookUpResult Validate(SidMapping sim);

        /// <summary>
        /// Tests the connection to the data source.
        /// </summary>
        /// <returns>A value which indicates the success of the test.</returns>
        ConnectResult TestCredentials(string user, string password);

        /// <summary>
        /// Collects the the sample data for specific list of sample identifiers and a specific list of analytes. 
        /// </summary>
        /// <param name="samples">The list of sample identifiere.</param>
        KeyKeyValueCollection<string,int,object> QueryData(List<SidMapping> samples );

        void Configure(DataProviderConfiguration config);

        /// <summary>
        /// Returns the information used to establish a connection. 
        /// </summary>
        string ConnectionString();

        /// <summary>
        /// Returns a new open connection. 
        /// </summary>
        IDbConnection BuildConnection();

        /// <summary>
        /// A event handler for requesting authentication information.
        /// </summary>
        event EventHandler<AuthenticationRequestEventArgs> AuthenticationRequest;

        /// <summary>
        /// A event handler for requesting the location of the linked xeml file.
        /// </summary>
        event EventHandler<XemlFilePathRequestEventArgs> XemlFilePathRequest;
    }

    public enum SidLookUpResult
    {
        /// <summary>
        /// if the foreign key map as valid syntax and the sample is known
        /// </summary>
        Valid,
        /// <summary>
        /// if the foreign key map is valid but the sample is unknown
        /// </summary>
        UnknownSample,
        /// <summary>
        /// if the key map is not valid
        /// </summary>
        UnsupportedMapping
    }
}
